var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var EventManager = require("AA_EventManager");
var LogManager = require("AA_LogManager");
var ResKeeper = require("AA_ResKeeper");
var CommonUtils = require("AA_CommonUtils");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var NodePoolMag = require("AA_NodePoolMag");
var UI_MosterLogic = require("AA_UI_MosterLogic");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_CreateMoster = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.pathsNode = null;
    t.onOver = null;
    t.isCreateMoster = false;
    t.mosterboshu = 0;
    t.mostertime = 0;
    t.mosteraindex = 0;
    t.chuguaicount = 0;
    t.isBoShuOver = false;
    t.isonguai = false;
    t.miaojishu = 0;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onEnable = function () {
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_Moster_FenLie, this.fenlieCreateMoster, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_ZhaoHuan_Moster, this.zhaoHuanCreateMoster, this);
  };
  _creator.prototype.setOver = function (e) {
    this.onOver = e;
  };
  _creator.prototype.resetBoShu = function () {
    this.mostertime = 0;
    this.mosteraindex = 0;
  };
  _creator.prototype.initMoster = function () {
    this.mostertime = 0;
    this.isCreateMoster = true;
  };
  _creator.prototype.zhaoHuanCreateMoster = function (e) {
    var t = this;
    var o = GameGlobalVariable.GameGlobalVariable.getMosterDis(e, this.pathsNode);
    this.scheduleOnce(function () {
      t.addMoster(e.mosterId, o.pos, null, o.tagindex);
    }, .1);
  };
  _creator.prototype.fenlieCreateMoster = function (e) {
    var t = this;
    var o = GameGlobalVariable.GameGlobalVariable.fenlieCreateMoster(e, this.pathsNode);
    this.scheduleOnce(function () {
      for (var n = 0; n < o.length; n++) {
        var i = o[n];
        t.addMoster(e.mosterId, i.pos, null, i.tagindex);
      }
    }, .1);
  };
  _creator.prototype.huishouMoster = function () {
    this.resetValue();
    var e = this.node.children;
    var t = e.length;
    for (var o = 0; o < t; o++) {
      var n = e[0];
      NodePoolMag.NodePoolMag.instance.recycleNode("moster_" + n.getComponent(UI_MosterLogic.default).mosterId, n);
    }
  };
  _creator.prototype.getNowBoShu = function () {
    var e = 1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel() ? Excel.Excel.shuiguotiaozhan(GameGlobalVariable.GameGlobalVariable.teshulevel) : Excel.Excel.shuiguoguanqia(GameGlobalVariable.GameGlobalVariable.nowlevel);
    var t = this.mosterboshu + 1;
    this.mosterboshu + 1 > e.levelboshuid.length && (t = e.levelboshuid.length);
    return t;
  };
  _creator.prototype.resetValue = function () {
    this.mostertime = 0;
    this.mosteraindex = 0;
    this.chuguaicount = 0;
  };
  _creator.prototype.createMoster = function () {
    var e = this;
    var t = (1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel() ? Excel.Excel.shuiguotiaozhan(GameGlobalVariable.GameGlobalVariable.teshulevel) : Excel.Excel.shuiguoguanqia(GameGlobalVariable.GameGlobalVariable.nowlevel)).levelboshuid;
    if (t[this.mosterboshu]) {
      var o = Excel.Excel.shuiguoboshu(t[this.mosterboshu]);
      var n = -1;
      var i = o.mosterid[this.mosteraindex];
      if (!i) {
        LogManager.LogMgr.debug("当前这一波怪物全部出完");
        return void this.onOver();
      }
      if (i[2] == this.mostertime) {
        n = this.mosteraindex;
        this.mosteraindex += 1;
      }
      if (-1 == n) {
        return;
      }
      this.mostertime = 0;
      var a = i[0];
      !function t(n) {
        e.addMoster(a, e.pathsNode.children[0].getPosition(), o);
        --n > 0 && e.scheduleOnce(function () {
          t(n);
        }, CommonUtils.default.limitInteger(1, 3) / 10);
      }(i[1]);
    } else {
      LogManager.LogMgr.debug("通关");
    }
  };
  _creator.prototype.addMoster = function (e, t, o, n) {
    undefined === n && (n = 1);
    return __awaiter(this, undefined, undefined, function () {
      var i;
      var a;
      var r;
      var c;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            1 == (i = Excel.Excel.shuiguoguaiwu(e)).boss && EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_SHOW_BOOS);
            a = i.mostertype;
            if (r = NodePoolMag.NodePoolMag.instance.getNode("moster_" + a)) {
              return [3, 2];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "prefabs/moster/moster" + a, cc.Prefab)];
            }
          case 1:
            c = s.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("moster_" + a, 1, c);
            r = NodePoolMag.NodePoolMag.instance.getNode("moster_" + a);
            s.label = 2;
          case 2:
            r.x = t.x;
            r.y = t.y;
            r.scale = 0;
            cc.tween(r).to(.1, {
              scale: 1.2
            }).to(.1, {
              scale: 1
            }).start();
            this.node.addChild(r);
            this.chuguaicount++;
            r.getComponent(UI_MosterLogic.default).setMosterInfo(e, this.pathsNode, this.chuguaicount, o, n);
            return [2];
        }
      });
    });
  };
  _creator.prototype.onCreateMoster = function (e) {
    this.miaojishu += e * GameGlobalVariable.GameGlobalVariable.jiasuState;
    if (this.miaojishu >= 1 && this.isCreateMoster) {
      this.miaojishu = 0;
      this.createMoster();
      this.mostertime += .5;
    }
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_Moster_FenLie, this.fenlieCreateMoster, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_ZhaoHuan_Moster, this.zhaoHuanCreateMoster, this);
  };
  __decorate([_property(cc.Node)], _creator.prototype, "pathsNode", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_CreateMoster;